----------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\afang\Box Sync\Shared_MS_SecretBallot2014\ReplicationFilesForDataverse\Analysis.log
  log type:  text
 opened on:  21 Jul 2017, 11:21:40

. 
. use PublicReplicationData.dta, clear

. 
. /*----------------------------
>  Calculate IPWs
> ----------------------------*/
. 
. * Calculate IPWs by sample definition
. foreach s in sdef {
  2. preserve
  3. contract treat if `s'==1, freq(freq) percent(pct)
  4. gen ipw_`s' = 1/(pct/100)
  5. list, t noobs
  6. keep treat ipw_`s'
  7. save ipw_`s'.dta, replace
  8. restore
  9. }

  +------------------------------------+
  | treatm~t   freq     pct   ipw_sdef |
  |------------------------------------|
  |        0   8704   68.33   1.463465 |
  |        1   4034   31.67    3.15766 |
  +------------------------------------+
(note: file ipw_sdef.dta not found)
file ipw_sdef.dta saved

. 
. * Merge back into main analysis file
. foreach s in sdef {
  2. merge m:1 treatment using ipw_`s'.dta
  3. drop _merge
  4. label var ipw_`s' "IPW for sample definition `s'==1"
  5. }

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                            18,941  (_merge==3)
    -----------------------------------------

. 
. * Delete temporary datasets
. foreach s in sdef {
  2. erase ipw_`s'.dta
  3. }

. 
. 
. /*----------------------------
> Table 1 and Table A3
> Estimate treatment effects
> ----------------------------*/
. 
. foreach s in sdef {
  2. 
. *Weighted, with covariates
. reg vote2014 treatment d_* age_miss days_miss if `s'==1 [aweight=ipw_`s'], robust
  3. qui sum vote2014 [aweight=ipw_`s'] if treat==0 & e(sample)
  4. local c_turnout = r(mean)
  5. outreg2 using "Table1_and_TableA3_RegressionEstimates.xls", replace ctitle("Weighted and, With Covariates") label dec(5) ///
>         addstat(Control Group Mean Turnout, `c_turnout') ///
>         addtext("Weighted?", Yes, "With Covariates?", Yes)
  6. 
. *Weighted, without covariates
. reg vote2014 treatment if `s'==1 [aweight=ipw_`s'], robust
  7. qui sum vote2014 [aweight=ipw_`s'] if treat==0 & e(sample)
  8. local c_turnout = r(mean)
  9. outreg2 using "Table1_and_TableA3_RegressionEstimates.xls", append ctitle("Weighted and, Without Covariates") label dec(5) ///
>         addstat(Control Group Mean Turnout, `c_turnout') ///
>         addtext("Weighted?", Yes, "With Covariates?", No)
 10. 
. *Unweighted, with covariates
. reg vote2014 treatment d_* age_miss days_miss if `s'==1, robust
 11. qui sum vote2014 if treat==0 & e(sample)
 12. local c_turnout = r(mean)
 13. outreg2 using "Table1_and_TableA3_RegressionEstimates.xls", append ctitle("Unweighted and, With Covariates") label dec(5) ///
>         addstat(Control Group Mean Turnout, `c_turnout') ///
>         addtext("Weighted?", No, "With Covariates?", Yes)
 14. 
. *Unweighted, without covariates
. reg vote2014 treatment if `s'==1, robust
 15. qui sum vote2014 if treat==0 & e(sample)
 16. local c_turnout = r(mean)
 17. outreg2 using "Table1_and_TableA3_RegressionEstimates.xls", append ctitle("Unweighted and, Without Covariates") label dec(5) ///
>         addstat(Control Group Mean Turnout, `c_turnout') ///
>         addtext("Weighted?", No, "With Covariates?", No)
 18. 
. }
(sum of wgt is   2.5476e+04)

Linear regression                               Number of obs     =     12,738
                                                F(10, 12727)      =      16.69
                                                Prob > F          =     0.0000
                                                R-squared         =     0.0015
                                                Root MSE          =     .11772

--------------------------------------------------------------------------------
               |               Robust
      vote2014 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
---------------+----------------------------------------------------------------
     treatment |   -.000486   .0022365    -0.22   0.828    -.0048698    .0038978
         d_age |  -.0000976    .000121    -0.81   0.420    -.0003348    .0001395
 d_gend_female |   .0024932   .0024255     1.03   0.304    -.0022611    .0072475
d_gend_unknown |   .0004296   .0034409     0.12   0.901     -.006315    .0071742
    d_race_blk |  -.0009363   .0028115    -0.33   0.739    -.0064473    .0045747
    d_race_hsp |  -.0140123   .0025667    -5.46   0.000    -.0190433   -.0089813
    d_race_oth |  -.0082748   .0068973    -1.20   0.230    -.0217946    .0052449
        d_days |  -7.25e-06   3.16e-06    -2.29   0.022    -.0000135   -1.06e-06
      age_miss |  -.0064793   .0024938    -2.60   0.009    -.0113674   -.0015911
     days_miss |  -.0141987   .0044685    -3.18   0.001    -.0229577   -.0054397
         _cons |    .032615   .0076413     4.27   0.000     .0176369    .0475931
--------------------------------------------------------------------------------
Table1_and_TableA3_RegressionEstimates.xls
dir : seeout
(sum of wgt is   2.5476e+04)

Linear regression                               Number of obs     =     12,738
                                                F(1, 12736)       =       0.03
                                                Prob > F          =     0.8707
                                                R-squared         =     0.0000
                                                Root MSE          =     .11776

------------------------------------------------------------------------------
             |               Robust
    vote2014 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
   treatment |  -.0003643   .0022378    -0.16   0.871    -.0047507    .0040221
       _cons |   .0142463   .0012703    11.21   0.000     .0117563    .0167363
------------------------------------------------------------------------------
Table1_and_TableA3_RegressionEstimates.xls
dir : seeout

Linear regression                               Number of obs     =     12,738
                                                F(10, 12727)      =      16.82
                                                Prob > F          =     0.0000
                                                R-squared         =     0.0016
                                                Root MSE          =     .11799

--------------------------------------------------------------------------------
               |               Robust
      vote2014 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
---------------+----------------------------------------------------------------
     treatment |  -.0004966   .0022399    -0.22   0.825    -.0048871    .0038938
         d_age |  -.0000827    .000121    -0.68   0.495    -.0003199    .0001546
 d_gend_female |   .0007663   .0022963     0.33   0.739    -.0037347    .0052673
d_gend_unknown |  -.0014774   .0030604    -0.48   0.629    -.0074763    .0045214
    d_race_blk |  -.0013181   .0026991    -0.49   0.625    -.0066088    .0039726
    d_race_hsp |  -.0142489   .0024732    -5.76   0.000    -.0190968    -.009401
    d_race_oth |  -.0061874   .0090787    -0.68   0.496    -.0239829    .0116081
        d_days |  -6.12e-06   3.05e-06    -2.00   0.045    -.0000121   -1.35e-07
      age_miss |    -.00758   .0023652    -3.20   0.001    -.0122162   -.0029438
     days_miss |  -.0162886    .004491    -3.63   0.000    -.0250916   -.0074855
         _cons |   .0323691   .0077042     4.20   0.000     .0172678    .0474704
--------------------------------------------------------------------------------
Table1_and_TableA3_RegressionEstimates.xls
dir : seeout

Linear regression                               Number of obs     =     12,738
                                                F(1, 12736)       =       0.03
                                                Prob > F          =     0.8707
                                                R-squared         =     0.0000
                                                Root MSE          =     .11804

------------------------------------------------------------------------------
             |               Robust
    vote2014 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
   treatment |  -.0003643   .0022378    -0.16   0.871    -.0047507    .0040221
       _cons |   .0142463   .0012703    11.21   0.000     .0117563    .0167363
------------------------------------------------------------------------------
Table1_and_TableA3_RegressionEstimates.xls
dir : seeout

. 
. 
. /*----------------------------
> Table A1
> Randomization checks
> ----------------------------*/
. 
. reg treatment d_* age_miss days_miss if sdef==1 [aweight=ipw_sdef]
(sum of wgt is   2.5476e+04)

      Source |       SS           df       MS      Number of obs   =    12,738
-------------+----------------------------------   F(9, 12728)     =      0.80
       Model |  1.79030401         9  .198922668   Prob > F        =    0.6205
    Residual |   3182.7097    12,728  .250055759   R-squared       =    0.0006
-------------+----------------------------------   Adj R-squared   =   -0.0001
       Total |      3184.5    12,737  .250019628   Root MSE        =    .50006

--------------------------------------------------------------------------------
     treatment |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
---------------+----------------------------------------------------------------
         d_age |  -.0003026   .0004388    -0.69   0.491    -.0011627    .0005576
 d_gend_female |  -.0038827   .0095997    -0.40   0.686    -.0226995    .0149342
d_gend_unknown |  -.0219106    .013732    -1.60   0.111    -.0488273    .0050062
    d_race_blk |   .0057574   .0111267     0.52   0.605    -.0160526    .0275674
    d_race_hsp |  -.0059089   .0474566    -0.12   0.901     -.098931    .0871131
    d_race_oth |    .007037   .0480168     0.15   0.883    -.0870833    .1011572
        d_days |  -.0000187   .0000138    -1.35   0.177    -.0000458    8.43e-06
      age_miss |  -.0059458   .0093253    -0.64   0.524    -.0242247    .0123332
     days_miss |  -.5005066   .4136732    -1.21   0.226    -1.311368     .310355
         _cons |   .5433381    .029575    18.37   0.000     .4853667    .6013095
--------------------------------------------------------------------------------

. testparm *

 ( 1)  d_age = 0
 ( 2)  d_gend_female = 0
 ( 3)  d_gend_unknown = 0
 ( 4)  d_race_blk = 0
 ( 5)  d_race_hsp = 0
 ( 6)  d_race_oth = 0
 ( 7)  d_days = 0
 ( 8)  age_miss = 0
 ( 9)  days_miss = 0

       F(  9, 12728) =    0.80
            Prob > F =    0.6205

. local fstat = round(r(F), 0.01)

. local p = round(r(p), 0.01)

. outreg2 using "TableA1_RandomizationCheck.xls", ctitle("Weighted") label addstat("F-statistic", `fstat', "F-stat p-value", `p') dec(3)
>  replace
TableA1_RandomizationCheck.xls
dir : seeout

. 
. reg treatment d_* age_miss days_miss if sdef==1

      Source |       SS           df       MS      Number of obs   =    12,738
-------------+----------------------------------   F(9, 12728)     =      0.65
       Model |  1.26370545         9  .140411717   Prob > F        =    0.7560
    Residual |  2755.20795    12,728  .216468255   R-squared       =    0.0005
-------------+----------------------------------   Adj R-squared   =   -0.0002
       Total |  2756.47166    12,737  .216414514   Root MSE        =    .46526

--------------------------------------------------------------------------------
     treatment |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
---------------+----------------------------------------------------------------
         d_age |  -.0002643   .0004083    -0.65   0.517    -.0010646    .0005359
 d_gend_female |  -.0033909   .0089411    -0.38   0.705    -.0209168     .014135
d_gend_unknown |  -.0188879   .0127349    -1.48   0.138    -.0438501    .0060744
    d_race_blk |   .0050123   .0103359     0.48   0.628    -.0152476    .0252723
    d_race_hsp |  -.0049194   .0439919    -0.11   0.911    -.0911501    .0813113
    d_race_oth |   .0063728    .044707     0.14   0.887    -.0812596    .0940052
        d_days |   -.000016   .0000128    -1.25   0.211    -.0000411    9.08e-06
      age_miss |  -.0051459    .008682    -0.59   0.553    -.0221639    .0118721
     days_miss |  -.3171356   .3293304    -0.96   0.336    -.9626727    .3284014
         _cons |   .3541318    .027427    12.91   0.000     .3003708    .4078928
--------------------------------------------------------------------------------

. testparm *

 ( 1)  d_age = 0
 ( 2)  d_gend_female = 0
 ( 3)  d_gend_unknown = 0
 ( 4)  d_race_blk = 0
 ( 5)  d_race_hsp = 0
 ( 6)  d_race_oth = 0
 ( 7)  d_days = 0
 ( 8)  age_miss = 0
 ( 9)  days_miss = 0

       F(  9, 12728) =    0.65
            Prob > F =    0.7560

. local fstat = round(r(F), 0.01)

. local p = round(r(p), 0.01)

. outreg2 using "TableA1_RandomizationCheck.xls", ctitle("Unweighted") label addstat("F-statistic", `fstat', "F-stat p-value", `p') dec(
> 3) append
TableA1_RandomizationCheck.xls
dir : seeout

. 
. /*----------------------------
> Table A2
> Balance table
> ----------------------------*/
. 
. outsum d_* age_miss days_miss [aweight=ipw_sdef] if sdef==1 & treatment == 0 using "TableA2_BalanceTable.xls", ctitle("Control") repla
> ce bracket addnote("Cells present weighted means and weighted standard deviations.")

. outsum d_* age_miss days_miss [aweight=ipw_sdef] if sdef==1 & treatment == 1 using "TableA2_BalanceTable.xls", ctitle("Treatment") app
> end bracket 

. 
. log close
      name:  <unnamed>
       log:  C:\Users\afang\Box Sync\Shared_MS_SecretBallot2014\ReplicationFilesForDataverse\Analysis.log
  log type:  text
 closed on:  21 Jul 2017, 11:21:42
----------------------------------------------------------------------------------------------------------------------------------------
